<?php

namespace app\api\controller\v1\user;

use app\common\controller\BaseController;
use think\Controller;
use think\Request;
use app\api\model\Course as CourseModel;
use app\api\model\TeacherCourse as TeacherCourseModel;

class Course extends BaseController
{
    protected $noNeedLogin = [''];
    /**
     * 课程记录
     */
    public function log()
    {
        $size = $this->request->get('size');
        $userId = $this->userId;
        $log = CourseModel::getUserLog($userId, $size);
        //累积天数
        $dayCounts = CourseModel::getdays($userId);
        //课时
        $hourCount = CourseModel::getHours($userId);
        //学习语种
        $languageCourseCount = TeacherCourseModel::getLanguageCounts($userId);
        //课次
        $courseCount = CourseModel::getCourseCounts($userId);
        $log->total() ? $this->success('', [
            'log' => $log->items(),
            'total' => $log->total(),
            'day_count' => $dayCounts,
            'hour_count' => $hourCount,
            'language_course_count' => $languageCourseCount,
            'course_count' => $courseCount
        ]) : $this->notFoundData();
    }

    /**
     * 全部预约课程进度
     */
    public function degree()
    {
        $courseOrderId = $this->notEmpty('course_order_id');
        $course = CourseModel::getAllReserve($courseOrderId);
        $courseCount = CourseModel::getAllCourseCounts($courseOrderId);
        $this->success('', [
            'course' => $course,
            'course_count' => $courseCount
        ]);
    }

    /**
     * 预约 - 完成课程进度
     */
    public function finish()
    {
        $courseOrderId = $this->notEmpty('course_order_id');
        $course = CourseModel::getOrtherFinish($courseOrderId);
        $courseCount = CourseModel::getAllCourseCounts($courseOrderId);
        $course['course_count'] = $courseCount;
        $this->success('', $course);
    }

    /**
     * 预约 - 课程预约进度
     */
    public function reserve()
    {
        $courseOrderId = $this->notEmpty('course_order_id');
        $course = CourseModel::getOrtherReserve($courseOrderId);
        $courseCount = CourseModel::getAllCourseCounts($courseOrderId);
        $this->success('', [
            'course' => $course,
            'course_count' => $courseCount
        ]);
    }
}
